import * as RNKeychain from 'react-native-keychain';

class Keychain {
  async set(key, value) {
    await RNKeychain.setGenericPassword(key, value, {
      accessible: RNKeychain.ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
      service: key,
    });
  }

  async get(key) {
    const result = await RNKeychain.getGenericPassword({
      service: key,
    });
    return result && result.password;
  }
}

export default new Keychain();
